package Frame;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

import Function.FCMapLibrary;
import VWorldGameStudio.FCMap;
import utils.FCDataSingles;

public class FCSaveMap extends JDialog {

	public FCSaveMap(FCMap map, FCMapLibrary mapl, MapEditJpanel mapj) {
		setModal(true);
		setTitle("保存地图");
		setBounds(0, 0, 205, 130);
		setLayout(null);
		setLocationRelativeTo(null);
		setResizable(false);

		JLabel qw = new JLabel("地图名称", JLabel.CENTER);
		qw.setBounds(10, 10, 180, 20);
		this.add(qw);

		JTextField as = new JTextField();
		as.setBounds(10, 40, 180, 20);
		//as.setEnabled(false);
		as.setText(map.getName());
		as.setDisabledTextColor(Color.black);
		this.add(as);

		JButton zx = new JButton("确认");
		zx.setBounds(10, 70, 180, 20);
		this.add(zx);

		zx.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (as.getText() != null && !as.getText().equals("")) {
					map.setName(as.getText().trim());
					FCDataSingles.getWriter().writeMapData(map);
					new FCTip("保存地图", "保存成功!");
					mapj.setSave();
					dispose();
				} else
					new FCTip("保存地图", "名称不得为空!");
			}
		});

		setVisible(true);
	}
}
